import 'package:FineArt/components/horizon_scroll.dart';
import 'package:FineArt/components/rounded_text.dart';
import 'package:FineArt/constants.dart';
import 'package:FineArt/core/utils/toast.dart';
import 'package:FineArt/core/widget/grid/grid_item.dart';
import 'package:FineArt/core/widget/grid/grid_item_photo.dart';
import 'package:FineArt/core/widget/grid/grid_item_teach.dart';
import 'package:FineArt/core/widget/list/article_item.dart';
import 'package:FineArt/page/tab/recommend/component/recommendItem.dart';
import 'package:FineArt/utils/log_util.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class TeachMainPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new _TeachMainPageState();
  }
}

class _TeachMainPageState extends State<TeachMainPage> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  int _count = 3;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    var width = MediaQuery
        .of(context)
        .size
        .width * 0.76;
    buildAction();
    return Scaffold(
        backgroundColor: white_bg,
        body: Column(
          children: [
            Padding(padding: EdgeInsets.symmetric(vertical: 2, horizontal: 2),
              child: Row(
                children: [
                  RoundedText(label: "全部",press: (){
                    print("tab all click>>>>");
                  }),
                  MHorizontalContainer(
                    categories: getHorData(), width: width,),
                  RoundedText(label: "下拉",
                  press: (){
                    print("more click");
                  },)

                ],
              ),),

            Expanded(
                child: EasyRefresh.custom(
                  header: MaterialHeader(),
                  footer: MaterialFooter(),
                  onRefresh: () async {
                    await Future.delayed(Duration(seconds: 1), () {
                      setState(() {
                        _count = 5;
                      });
                    });
                  },
                  onLoad: () async {
                    await Future.delayed(Duration(seconds: 1), () {
                      setState(() {
                        _count += 5;
                      });
                    });
                  },
                  slivers: <Widget>[
                    SliverPadding(
                        padding: EdgeInsets.only(top: 1),
                        sliver: SliverList(
                          delegate: SliverChildBuilderDelegate(
                                (BuildContext context, int index) {
                              //创建子widget
                              var action = actions[index];
                              return ListItemTeach(
                                  url: action.url,
                                  onTap: () {
                                    ToastUtils.toast('点击-->${action.url}');
                                  });
                            },
                            childCount: actions.length,
                          ),
                        )),

                    //=====列表=====//
                  ],
                )),
          ],
        ));
  }

  static const String TUrl =
      "https://cdn.rouding.cn/imagesrc-s/jpeg/201506-11-2B09E2AFEEABB4D4F23F2F118F6266E1-th.jpg";
  final List<ActionTeachItem> actions = [

  ];

  void buildAction(){
    for(int i=0;i<10;i++){
      actions.add(ActionTeachItem(TUrl));
    }
  }
  List getHorData() {
    List hData = [];
    for (var i = 0; i < 2; i++) {
      hData.add("石膏照片");
      hData.add("素描静物");
      hData.add("色彩静物");
    }

    return hData;
  }
}
